import request from '@/utils/request';
import { hasIsSw,isCustome,isLianxiSite,isCustomeSubject} from '../utils/utils';;
import { baseurl } from "./baseurl";
export interface addPaperParams {
  name: string;
  subject: string;
  template: string;
  complexity: string;
  total: string;
  test_type: string;
  multiple_num: string;
  multiple_score: string;
  multiple_deduct: string;
  multiple_mistake: string;
  choices_num: string;
  choices_score: string;
  choices_deduct: string;
  choices_mistake: string;
  judge_num: string;
  judge_score: string;
  judge_deduct: string;
  judge_mistake: string;
  test_time: string;
  fail: string;
  pass: string;
  good: string;
  excellent: string;
  people: string;
  selection_rules: string;
  selection_ruless: any;
}
export async function addPaper(params: addPaperParams) {
  const data = {
    name: params.name,
    subject: [params.subject],
    template: params.template,
    complexity: params.complexity,
    total: params.total,
    test_type: params.test_type,
    multiple_num: params.multiple_num,
    multiple_score: params.multiple_score,
    multiple_deduct: params.multiple_deduct,
    multiple_mistake: params.multiple_mistake,
    choices_num: params.choices_num,
    choices_score: params.choices_score,
    choices_deduct: params.choices_deduct,
    choices_mistake: params.choices_mistake,
    judge_num: params.judge_num,
    judge_score: params.judge_score,
    judge_deduct: params.judge_deduct,
    judge_mistake: params.judge_mistake,
    test_time: params.test_time,
    fail: params.fail,
    pass: params.pass,
    good: params.good,
    excellent: params.excellent,
    people: params.people,
    selection_rules: params.selection_rules,
    selection_ruless: params.selection_ruless,
    type: '1',
    is_sw:location.href.includes('tzExamInfo')?'1':'2'
  }
  if(!hasIsSw()){
    delete data.is_sw
  }
  return request(`${baseurl}index/index/paper_save`, {
    method: 'POST',
    data
  });
}





export interface editPaperParams {
  id: string;
  name: string;
  subject: string;
  template: string;
  complexity: string;
  total: string;
  test_type: string;
  multiple_num: string;
  multiple_score: string;
  multiple_deduct: string;
  multiple_mistake: string;
  choices_num: string;
  choices_score: string;
  choices_deduct: string;
  choices_mistake: string;
  judge_num: string;
  judge_score: string;
  judge_deduct: string;
  judge_mistake: string;
  test_time: string;
  fail: string;
  pass: string;
  good: string;
  excellent: string;
  people: string;
  selection_rules: string;
  selection_ruless: any;
}
export async function editPaper(params: editPaperParams) {
  const data =  {
    id:params.id,
    name: params.name,
    subject: params.subject,
    template: params.template,
    complexity: params.complexity,
    total: params.total,
    test_type: params.test_type,
    multiple_num: params.multiple_num,
    multiple_score: params.multiple_score,
    multiple_deduct: params.multiple_deduct,
    multiple_mistake: params.multiple_mistake,
    choices_num: params.choices_num,
    choices_score: params.choices_score,
    choices_deduct: params.choices_deduct,
    choices_mistake: params.choices_mistake,
    judge_num: params.judge_num,
    judge_score: params.judge_score,
    judge_deduct: params.judge_deduct,
    judge_mistake: params.judge_mistake,
    test_time: params.test_time,
    fail: params.fail,
    pass: params.pass,
    good: params.good,
    excellent: params.excellent,
    people: params.people,
    selection_rules: params.selection_rules,
    selection_ruless: params.selection_ruless,
    type: '1',
    is_sw:location.href.includes('tzExamInfo')?'1':'2'
  }
  if(!hasIsSw()){
    delete data.is_sw
  }
  return request(`${baseurl}index/index/up_paper`, {
    method: 'POST',
    data
  });
}



export interface getSubjectNumParams {
  type: string;
  subject: any;
  complexity: string;
}
export async function getSubjectNum(params: getSubjectNumParams) {
  const data = new FormData();
  data.append('type', params.type);
  data.append('subject', params.subject);
  data.append('complexity', params.type);
  if(hasIsSw()){
    if(location.href.includes('tzExamInfo')){
      data.append('is_sw', '1');
    }else{
      data.append('is_sw','2');
    }
  }
  if(isCustome()&&isCustomeSubject(params.subject)){
    return request(`${baseurl}index/index/subject_num_optional`, {
      method: 'POST',
      data,
    });
  }
  return request(`${baseurl}index/index/subject_num`, {
    method: 'POST',
    data,
  });
}

export interface addPaperTemplateParams {
  template_name: string;
  complexity: string;
  total: string;
  test_type: string;
  multiple_num: string;
  multiple_score: string;
  multiple_deduct: string;
  multiple_mistake: string;
  choices_num: string;
  choices_score: string;
  choices_deduct: string;
  choices_mistake: string;
  judge_num: string;
  judge_score: string;
  judge_deduct: string;
  judge_mistake: string;
  test_time: string;
  fail:string;
  pass:string;
  good:string;
  excellent:string;
}
export async function addPaperTemplate(params: addPaperTemplateParams) {
  const data = {
    template_name: params.template_name,
    complexity: params.complexity,
    total: params.total,
    test_type: params.test_type,
    multiple_num: params.multiple_num,
    multiple_score: params.multiple_score,
    multiple_deduct: params.multiple_deduct,
    multiple_mistake: params.multiple_mistake,
    choices_num: params.choices_num,
    choices_score: params.choices_score,
    choices_deduct: params.choices_deduct,
    choices_mistake: params.choices_mistake,
    judge_num: params.judge_num,
    judge_score: params.judge_score,
    judge_deduct: params.judge_deduct,
    judge_mistake: params.judge_mistake,
    test_time: params.test_time,
    subject: '',
    people: '',
    selection_ruless: '',
    selection_rules: '',
    type: '2',
    fail:params.fail,
    pass:params.pass,
    good:params.good,
    excellent:params.excellent,
    is_sw:location.href.includes('addTzTemplate')?'1':'2'
  }
  if(!hasIsSw()){
    delete data.is_sw
  }
  return request(`${baseurl}index/index/paper_save`, {
    method: 'POST',
    data
  });
}

export async function getTemplateList(params: any) {
  const data = new FormData();
  data.append('template_name', params.template_name);
  if(hasIsSw()){
    if(location.href.includes('tzExamInfo')){//1是特种作业人员 2是特种设备人员
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }

  return request(`${baseurl}index/index/template_list`, {
    method: 'POST',
    data
  });
}
export async function deleteTemplateList(params: any) {
  /* 删除试卷模板 */
  const data = new FormData();
  data.append('id', params.id);
  if(hasIsSw()){
    if(location.href.includes('tzExamInfo')){//1是特种作业人员 2是特种设备人员
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }
  return request(`${baseurl}index/index/del_template`, {
    method: 'POST',
    data
  });
}


export async function getTemplateDetail(params: any) {
  const data = new FormData();
  data.append('id', params.id);
  data.append('type','2');
  if(hasIsSw()){
    if(location.href.includes('tzExamInfo')){//1是特种作业人员 2是特种设备人员
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }
  return request(`${baseurl}index/index/template_detail`, {
    method: 'POST',
    data,
  });
}



export interface editPaperTemplateParams {
  template_name: string;
  complexity: string;
  total: string;
  test_type: string;
  multiple_num: string;
  multiple_score: string;
  multiple_deduct: string;
  multiple_mistake: string;
  choices_num: string;
  choices_score: string;
  choices_deduct: string;
  choices_mistake: string;
  judge_num: string;
  judge_score: string;
  judge_deduct: string;
  judge_mistake: string;
  test_time: string;
  id: string;
  fail:string;
  pass:string;
  good:string;
  excellent:string;
}
export async function editPaperTemplate(params: editPaperTemplateParams) {
  const data = new FormData();
  data.append('id', params.id);
  data.append('template_name', params.template_name);
  data.append('complexity', params.complexity);
  data.append('total', params.total);
  data.append('test_type', params.test_type);
  data.append('multiple_num', params.multiple_num)
  data.append('multiple_score', params.multiple_score)
  data.append('multiple_deduct', params.multiple_deduct)
  data.append('multiple_mistake', params.multiple_mistake)
  data.append('choices_num', params.choices_num)
  data.append('choices_score', params.choices_score)
  data.append('choices_deduct', params.choices_deduct)
  data.append('choices_mistake', params.choices_mistake)
  data.append('judge_num', params.judge_num)
  data.append('judge_score', params.judge_score)
  data.append('judge_deduct', params.judge_deduct)
  data.append('judge_mistake', params.judge_mistake)
  data.append('test_time', params.test_time)
  data.append('fail', params.fail)
  data.append('pass', params.pass)
  data.append('good', params.good)
  data.append('excellent', params.excellent)
  if(hasIsSw()){
    if(location.href.includes('tzExamInfo')){//1是特种作业人员 2是特种设备人员
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }
  return request(`${baseurl}index/index/up_template`, {
    method: 'POST',
    data
  });
}



export interface getPaperListParams {
  page:string;
  subject:string;
  complexity:string;
  test_type:string;
  name:string;
}
export async function getPaperList(params: getPaperListParams) {
  const data = new FormData();
  data.append('page',params.page)
  data.append('subject',params.subject)
  data.append('complexity',params.complexity)
  data.append('test_type',params.test_type)
  data.append('name',params.name)
  if(hasIsSw()){
    if(location.href.includes('tzExamInfo')){//1是特种作业人员 2是特种设备人员
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }
  return request(`${baseurl}index/index/paper_list`, {
    method: 'POST',
    data
  });
}


export async function getPaperDetail(params: any) {
  /* 试卷详情 */
  const data = new FormData();
  data.append('id', params.id);
  data.append('type','1');
  if(hasIsSw()){
    if(location.href.includes('tzExamInfo')){//1是特种作业人员 2是特种设备人员
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }
  return request(`${baseurl}index/index/template_detail`, {
    method: 'POST',
    data,
  });
}

export async function getManualPaperDetail(params: any) {
  /* 试卷详情 */
  const data = new FormData();
  data.append('id', params.id);
  data.append('type','3');
  if(hasIsSw()){
    if(location.href.includes('tzExamInfo')){//1是特种作业人员 2是特种设备人员
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }
  return request(`${baseurl}index/index/template_detail`, {
    method: 'POST',
    data,
  });
}


export async function getPaperAnswerDetail(params: any) {
  /* 获取答案和试题 */
  const data = new FormData();
  data.append('id', params.id);
  if(hasIsSw()){
   const is_sw = JSON.parse( localStorage.getItem('userinfo')||'{}').is_sw;
     data.append('is_sw', is_sw);
  }
  return request(`${baseurl}index/index/paper_answer`, {
    method: 'POST',
    data,
  });
}

export async function getManualPaperAnswerDetail(params: any) {
  /* 获取人工答案和试题 */
  const data = new FormData();
  data.append('id', params.id);
  if(hasIsSw()){
    const is_sw = JSON.parse( localStorage.getItem('userinfo')||'{}').is_sw;
      data.append('is_sw', is_sw);
   }
  return request(`${baseurl}index/index/paper_answers`, {
    method: 'POST',
    data,
  });
}



export interface addPaperManualParams {
  name: string;
  subject: string;
  template: string;
  complexity: string;
  total: string;
  test_type: string;
  multiple_num: string;
  multiple_score: string;
  multiple_deduct: string;
  multiple_mistake: string;
  choices_num: string;
  choices_score: string;
  choices_deduct: string;
  choices_mistake: string;
  judge_num: string;
  judge_score: string;
  judge_deduct: string;
  judge_mistake: string;
  test_time: string;
  fail: string;
  pass: string;
  good: string;
  excellent: string;
  people: string;
  choice:string;
  choices:string;
  judge:string;
}
export async function addPaperManual(params: addPaperManualParams) {
  const data =  {
    name: params.name,
    subject: [params.subject],
    template: params.template,
    complexity: params.complexity,
    total: params.total,
    test_type: params.test_type,
    multiple_num: params.multiple_num,
    multiple_score: params.multiple_score,
    multiple_deduct: params.multiple_deduct,
    multiple_mistake: params.multiple_mistake,
    choices_num: params.choices_num,
    choices_score: params.choices_score,
    choices_deduct: params.choices_deduct,
    choices_mistake: params.choices_mistake,
    judge_num: params.judge_num,
    judge_score: params.judge_score,
    judge_deduct: params.judge_deduct,
    judge_mistake: params.judge_mistake,
    test_time: params.test_time,
    fail: params.fail,
    pass: params.pass,
    good: params.good,
    excellent: params.excellent,
    people: params.people,
    choice:params.choice,
    choices:params.choices,
    judge:params.judge,
    type: '1',
    is_sw:location.href.includes('tzExamInfo')?'1':'2'
  }
  if(!hasIsSw()){
    delete data.is_sw
  }
  return request(`${baseurl}index/index/artificial_paper`, {
    method: 'POST',
    data
  });
}

export interface editPaperManualParams {
  name: string;
  subject: string;
  template: string;
  complexity: string;
  total: string;
  test_type: string;
  multiple_num: string;
  multiple_score: string;
  multiple_deduct: string;
  multiple_mistake: string;
  choices_num: string;
  choices_score: string;
  choices_deduct: string;
  choices_mistake: string;
  judge_num: string;
  judge_score: string;
  judge_deduct: string;
  judge_mistake: string;
  test_time: string;
  fail: string;
  pass: string;
  good: string;
  excellent: string;
  people: string;
  choice:string;
  choices:string;
  judge:string;
  id:string;
}
export async function editPaperManual(params: editPaperManualParams) {
  const data=  {
    name: params.name,
    subject: params.subject,
    template: params.template,
    complexity: params.complexity,
    total: params.total,
    test_type: params.test_type,
    multiple_num: params.multiple_num,
    multiple_score: params.multiple_score,
    multiple_deduct: params.multiple_deduct,
    multiple_mistake: params.multiple_mistake,
    choices_num: params.choices_num,
    choices_score: params.choices_score,
    choices_deduct: params.choices_deduct,
    choices_mistake: params.choices_mistake,
    judge_num: params.judge_num,
    judge_score: params.judge_score,
    judge_deduct: params.judge_deduct,
    judge_mistake: params.judge_mistake,
    test_time: params.test_time,
    fail: params.fail,
    pass: params.pass,
    good: params.good,
    excellent: params.excellent,
    people: params.people,
    choice:params.choice,
    choices:params.choices,
    judge:params.judge,
    selection_ruless:'',
    selection_rules:'',
    type: '3',
    id:params.id,
    is_sw:location.href.includes('tzExamInfo')?'1':'2'
  }
  if(!hasIsSw()){
    delete data.is_sw
  }
  return request(`${baseurl}index/index/up_paper`, {
    method: 'POST',
    data
  });
}


export async function getPaperAnalyzeDetail(params: any) {
  /* 获取试卷统计上面的信息 */
  const data = new FormData();
  const userinfo = JSON.parse(localStorage.getItem('userinfo'));
  data.append('id', params.id);
  data.append('student_type', userinfo.student_type);
  if(hasIsSw()){
    if(location.href.includes('tzExamInfo')){
      data.append('is_sw', '1');
    }else{
      data.append('is_sw','2');
    }
  }

  return request(`${baseurl}index/index/topic_statistics`, {
    method: 'POST',
    data,
  });
}
export async function getPaperAnalyzeList(params: any) {
  /* 获取试卷统计列表 */
  const data = new FormData();
  data.append('id', params.id);
  data.append('start_date', params.start_date);
  data.append('end_date', params.end_date);
  data.append('student_type', params.student_type);
  data.append('name', params.name);
  data.append('id_number', params.id_number);
  if(hasIsSw()){
    if(location.href.includes('tzExamInfo')){
      data.append('is_sw', '1');
    }else{
      data.append('is_sw','2');
    }
  }

  return request(`${baseurl}index/index/topic_statistic`, {
    method: 'POST',
    data,
  });
}


export async function deletePaper(params: any) {
  /* 删除试卷 */
  const data = new FormData();
  data.append('id', params.id);
  if(hasIsSw()){
    if(location.href.includes('tzExamInfo')){
      data.append('is_sw', '1');
    }else{
      data.append('is_sw','2');
    }
  }

  return request(`${baseurl}index/index/paper_del`, {
    method: 'POST',
    data,
  });
}

export async function selectTest(params: any) {
  /* 删除试卷 */
  const data = new FormData();
  data.append('subject', params.subject);
  if(hasIsSw()){
    if(location.href.includes('tzExamInfo')){
      data.append('is_sw', '1');
    }else{
      data.append('is_sw','2');
    }
  }

  return request(`${baseurl}index/index/select_test`, {
    method: 'POST',
    data,
  });
}


